home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-admin / users.php < prev    next >
Encoding:
PHP Script  |  2004-12-16  |  10.6 KB  |  331 lines

  1. <?php
  2. require_once('../wp-includes/wp-l10n.php');
  3.  
  4. $title = __('Users');
  5. /* <Team> */
  6.     
  7. $wpvarstoreset = array('action','standalone','redirect','profile');
  8. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  9.     $wpvar = $wpvarstoreset[$i];
  10.     if (!isset($$wpvar)) {
  11.         if (empty($_POST["$wpvar"])) {
  12.             if (empty($_GET["$wpvar"])) {
  13.                 $$wpvar = '';
  14.             } else {
  15.                 $$wpvar = $_GET["$wpvar"];
  16.             }
  17.         } else {
  18.             $$wpvar = $_POST["$wpvar"];
  19.         }
  20.     }
  21. }
  22.  
  23. switch ($action) {
  24. case 'adduser':
  25.     $standalone = 1;
  26.     require_once('admin-header.php');
  27.  
  28.     check_admin_referer();
  29.  
  30.     function filter($value)    {
  31.         return ereg('^[a-zA-Z0-9\_-\|]+$',$value);
  32.     }
  33.  
  34.     $user_login = wp_specialchars($_POST['user_login']);
  35.     $pass1 = $_POST['pass1'];
  36.     $pass2 = $_POST['pass2'];
  37.     $user_email = wp_specialchars($_POST['email']);
  38.     $user_firstname = wp_specialchars($_POST['firstname']);
  39.     $user_lastname = wp_specialchars($_POST['lastname']);
  40.         
  41.     /* checking login has been typed */
  42.     if ($user_login == '') {
  43.         die (__('<strong>ERROR</strong>: Please enter a login.'));
  44.     }
  45.  
  46.     /* checking the password has been typed twice */
  47.     if ($pass1 == '' || $pass2 == '') {
  48.         die (__('<strong>ERROR</strong>: Please enter your password twice.'));
  49.     }
  50.  
  51.     /* checking the password has been typed twice the same */
  52.     if ($pass1 != $pass2)    {
  53.         die (__('<strong>ERROR</strong>: Please type the same password in the two password fields.'));
  54.     }
  55.     $user_nickname = $user_login;
  56.  
  57.     /* checking the login isn't already used by another user */
  58.     $loginthere = $wpdb->get_var("SELECT user_login FROM $tableusers WHERE user_login = '$user_login'");
  59.     if ($loginthere) {
  60.         die (__('<strong>ERROR</strong>: This login is already registered, please choose another one.'));
  61.     }
  62.  
  63.     /* checking e-mail address */
  64.     if (empty($_POST["email"])) {
  65.         die (__("<strong>ERROR</strong>: please type an e-mail address"));
  66.         return false;
  67.     } else if (!is_email($_POST["email"])) {
  68.         die (__("<strong>ERROR</strong>: the email address isn't correct"));
  69.         return false;
  70.     }
  71.  
  72.     $user_login = addslashes(stripslashes($user_login));
  73.     $pass1 = addslashes(stripslashes($pass1));
  74.     $user_nickname = addslashes(stripslashes($user_nickname));
  75.     $user_nicename = sanitize_title($user_nickname);
  76.     $user_firstname = addslashes(stripslashes($user_firstname));
  77.     $user_lastname = addslashes(stripslashes($user_lastname));
  78.     $now = gmdate('Y-m-d H:i:s');
  79.     $new_users_can_blog = get_settings('new_users_can_blog');
  80.  
  81.     $result = $wpdb->query("INSERT INTO $tableusers 
  82.         (user_login, user_pass, user_nickname, user_email, user_ip, user_domain, user_browser, dateYMDhour, user_level, user_idmode, user_firstname, user_lastname, user_nicename)
  83.     VALUES 
  84.         ('$user_login', MD5('$pass1'), '$user_nickname', '$user_email', '$user_ip', '$user_domain', '$user_browser', '$now', '$new_users_can_blog', 'nickname', '$user_firstname', '$user_lastname', '$user_nicename')");
  85.     
  86.     if ($result == false) {
  87.         die (__('<strong>ERROR</strong>: Couldn’t register you!'));
  88.     }
  89.  
  90.     $stars = '';
  91.     for ($i = 0; $i < strlen($pass1); $i = $i + 1) {
  92.         $stars .= '*';
  93.     }
  94.  
  95.     $message  = 'New user registration on your blog ' . get_settings('blogname') . ":\r\n\r\n";
  96.     $message .= "Login: $user_login\r\n\r\nE-mail: $user_email";
  97.  
  98.     @mail(get_settings('admin_email'), '[' . get_settings('blogname') . '] New User Registration', $message);
  99.     header('Location: users.php');
  100. break;
  101.  
  102. case 'promote':
  103.  
  104.     $standalone = 1;
  105.     require_once('admin-header.php');
  106.  
  107.     check_admin_referer();
  108.  
  109.     if (empty($_GET['prom'])) {
  110.         header('Location: users.php');
  111.     }
  112.  
  113.     $id = $_GET['id'];
  114.     $prom = $_GET['prom'];
  115.  
  116.     $user_data = get_userdata($id);
  117.     $usertopromote_level = $user_data->user_level;
  118.  
  119.     if ($user_level <= $usertopromote_level) {
  120.         die(__('Can’t change the level of a user whose level is higher than yours.'));
  121.     }
  122.  
  123.     if ('up' == $prom) {
  124.         $new_level = $usertopromote_level + 1;
  125.         $sql="UPDATE $tableusers SET user_level=$new_level WHERE ID = $id AND $new_level < $user_level";
  126.     } elseif ('down' == $prom) {
  127.         $new_level = $usertopromote_level - 1;
  128.         $sql="UPDATE $tableusers SET user_level=$new_level WHERE ID = $id AND $new_level < $user_level";
  129.     }
  130.     $result = $wpdb->query($sql);
  131.  
  132.     header('Location: users.php');
  133.  
  134. break;
  135.  
  136. case 'delete':
  137.  
  138.     $standalone = 1;
  139.     require_once('admin-header.php');
  140.  
  141.     check_admin_referer();
  142.  
  143.     $id = intval($_GET['id']);
  144.  
  145.     if (!$id) {
  146.         header('Location: users.php');
  147.     }
  148.  
  149.     $user_data = get_userdata($id);
  150.     $usertodelete_level = $user_data->user_level;
  151.  
  152.     if ($user_level <= $usertodelete_level)
  153.         die(__('Can’t delete a user whose level is higher than yours.'));
  154.  
  155.     $post_ids = $wpdb->get_col("SELECT ID FROM $tableposts WHERE post_author = $id");
  156.     if ($post_ids) {
  157.         $post_ids = implode(',', $post_ids);
  158.         
  159.         // Delete comments, *backs
  160.         $wpdb->query("DELETE FROM $tablecomments WHERE comment_post_ID IN ($post_ids)");
  161.         // Clean cats
  162.         $wpdb->query("DELETE FROM $tablepost2cat WHERE post_id IN ($post_ids)");
  163.         // Clean post_meta
  164.         $wpdb->query("DELETE FROM $tablepostmeta WHERE post_id IN ($post_ids)");
  165.         // Clean links
  166.         $wpdb->query("DELETE FROM $tablelinks WHERE link_owner = $id");
  167.         // Delete posts
  168.         $wpdb->query("DELETE FROM $tableposts WHERE post_author = $id");
  169.     }
  170.  
  171.     // FINALLY, delete user
  172.     $wpdb->query("DELETE FROM $tableusers WHERE ID = $id");
  173.     header('Location: users.php?deleted=true');
  174.  
  175. break;
  176.  
  177. default:
  178.     
  179.     $standalone = 0;
  180.     include ('admin-header.php');
  181.     ?>
  182. <?php if (isset($_GET['deleted'])) : ?>
  183. <div class="updated"><p><?php _e('User deleted.') ?></p></div>
  184. <?php endif; ?>
  185. <div class="wrap">
  186.   <h2><?php _e('Authors') ?></h2>
  187.   <table cellpadding="3" cellspacing="3" width="100%">
  188.     <tr>
  189.     <th><?php _e('ID') ?></th>
  190.     <th><?php _e('Nickname') ?></th>
  191.     <th><?php _e('Name') ?></th>
  192.     <th><?php _e('E-mail') ?></th>
  193.     <th><?php _e('Website') ?></th>
  194.     <th><?php _e('Level') ?></th>
  195.     <th><?php _e('Posts') ?></th>
  196.     </tr>
  197.     <?php
  198.     $users = $wpdb->get_results("SELECT ID FROM $tableusers WHERE user_level > 0 ORDER BY ID");
  199.     $style = '';
  200.     foreach ($users as $user) {
  201.         $user_data = get_userdata($user->ID);
  202.         $email = $user_data->user_email;
  203.         $url = $user_data->user_url;
  204.         $short_url = str_replace('http://', '', stripslashes($url));
  205.         $short_url = str_replace('www.', '', $short_url);
  206.         if ('/' == substr($short_url, -1))
  207.             $short_url = substr($short_url, 0, -1);
  208.         if (strlen($short_url) > 35)
  209.         $short_url =  substr($short_url, 0, 32).'...';
  210.         $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
  211.         $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $tableposts WHERE post_author = $user->ID and post_status = 'publish'");
  212.         if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_data->ID' title='" . __('View posts') . "'>$numposts</a>";
  213.         echo "
  214. <tr $style>
  215.     <td align='center'>$user_data->ID</td>
  216.     <td><strong>$user_data->user_nickname</strong></td>
  217.     <td>$user_data->user_firstname $user_data->user_lastname</td>
  218.     <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
  219.     <td><a href='$url' title='website: $url'>$short_url</a></td>
  220.     <td align='center'>";
  221.     if (($user_level >= 2) and ($user_level > $user_data->user_level) and ($user_data->user_level > 0))
  222.         echo " <a href=\"users.php?action=promote&id=".$user_data->ID."&prom=down\">-</a> ";
  223.     echo $user_data->user_level;
  224.     if (($user_level >= 2) and ($user_level > ($user_data->user_level + 1)))
  225.         echo " <a href=\"users.php?action=promote&id=".$user_data->ID."&prom=up\">+</a> ";
  226.     echo "<td align='right'>$numposts</td>";
  227.     echo '</tr>';
  228.     }
  229.     
  230.     ?>
  231.     
  232.   </table>
  233. </div>
  234.  
  235. <?php
  236.     $users = $wpdb->get_results("SELECT * FROM $tableusers WHERE user_level = 0 ORDER BY ID");
  237.     if ($users) {
  238. ?>
  239. <div class="wrap">
  240.     <h2><?php _e('Users') ?></h2>
  241.     <table cellpadding="3" cellspacing="3" width="100%">
  242.     <tr>
  243.         <th><?php _e('ID') ?></th>
  244.         <th><?php _e('Nickname') ?></th>
  245.         <th><?php _e('Name') ?></th>
  246.         <th><?php _e('E-mail') ?></th>
  247.         <th><?php _e('Website') ?></th>
  248.         <th><?php _e('Level') ?></th>
  249.     </tr>
  250.     <?php
  251.     foreach ($users as $user) {
  252.         $user_data = get_userdata($user->ID);
  253.         $email = $user_data->user_email;
  254.         $url = $user_data->user_url;
  255.         $short_url = str_replace('http://', '', stripslashes($url));
  256.         $short_url = str_replace('www.', '', $short_url);
  257.         if ('/' == substr($short_url, -1))
  258.             $short_url = substr($short_url, 0, -1);
  259.         if (strlen($short_url) > 35)
  260.         $short_url =  substr($short_url, 0, 32).'...';
  261.         $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
  262. echo "\n<tr $style>
  263. <td align='center'>$user_data->ID</td>
  264. <td><strong>$user_data->user_nickname</td>
  265. <td>$user_data->user_firstname $user_data->user_lastname</td>
  266. <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
  267. <td><a href='$url' title='website: $url'>$short_url</a></td>
  268. <td align='center'>";
  269.         if ($user_level >= 3)
  270.             echo " <a href=\"users.php?action=delete&id=".$user_data->ID."\" style=\"color:red;font-weight:bold;\">X</a> ";
  271.         echo $user_data->user_level;
  272.         if ($user_level >= 2)
  273.             echo " <a href=\"users.php?action=promote&id=".$user_data->ID."&prom=up\">+</a> ";    
  274.         echo "</td>\n</tr>\n";
  275.     }
  276.     ?>
  277.     
  278.     </table>
  279.       <?php _e('<p>To delete a user, bring his level to zero, then click on the red X.<br />
  280.     <strong>Warning:</strong> deleting a user also deletes all posts made by this user.</p>') ?>
  281. </div>
  282.  
  283.     <?php 
  284.     } ?>
  285. <div class="wrap">
  286. <h2><?php _e('Add User') ?></h2>
  287. <?php printf(__('<p>Users can <a href="%s/wp-register.php">register themselves</a> or you can manually create users here.</p>'), get_settings('siteurl')); ?>
  288. <form action="" method="post" name="adduser" id="adduser">
  289.   <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  290.     <tr>
  291.       <th scope="row" width="33%"><?php _e('Nickname') ?>
  292.       <input name="action" type="hidden" id="action" value="adduser" /></th>
  293.       <td width="66%"><input name="user_login" type="text" id="user_login" /></td>
  294.     </tr>
  295.     <tr>
  296.       <th scope="row"><?php _e('First Name') ?> </th>
  297.       <td><input name="firstname" type="text" id="firstname" /></td>
  298.     </tr>
  299.     <tr>
  300.       <th scope="row"><?php _e('Last Name') ?> </th>
  301.       <td><input name="lastname" type="text" id="lastname" /></td>
  302.     </tr>
  303.     <tr>
  304.       <th scope="row"><?php _e('E-mail') ?></th>
  305.       <td><input name="email" type="text" id="email" /></td>
  306.     </tr>
  307.     <tr>
  308.       <th scope="row"><?php _e('Website') ?></th>
  309.       <td><input name="uri" type="text" id="uri" /></td>
  310.     </tr>
  311.     <tr>
  312.       <th scope="row"><?php _e('Password (twice)') ?> </th>
  313.       <td><input name="pass1" type="password" id="pass1" />
  314.       <br />
  315.       <input name="pass2" type="password" id="pass2" /></td>
  316.     </tr>
  317.   </table>
  318.   <p class="submit">
  319.     <input name="adduser" type="submit" id="adduser" value="<?php _e('Add User') ?> »">
  320.   </p>
  321.   </form>
  322. </div>
  323.     <?php
  324.  
  325. break;
  326. }
  327.     
  328. /* </Team> */
  329. include('admin-footer.php');
  330. ?>
  331.